#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#include "pub_lib.h"

//dot product: sdot
//[2,7,1] . [8,2,8] = 38
void test_dot_product(void)
{
	float  res;

	Vector3 x = {2.0, 7.0, 1.0};
	Vector3 y = {8.0, 2.0, 8.0};
	res = Vector3DotProduct(x, y);

	printf("test sdot function\n");
	printf("[%.3f %.3f %.3f] . ", x.x, x.y, x.z);
	printf("[%.3f %.3f %.3f] = ", y.x, y.y, y.z);
	printf("%.1f \n\n", res);
}

/*
 * * 线性代数第6版，第2章，习题1，第一个小题的答案
 * A = [
 *  4 3 1
 *  1 -2 3
 *  5 7 0
 *  ]
 *  vector = [7 2 1]
 *  A * vector = [35 6 49]
 *
 * */
void test_matrix_product_vector(void)
{

	Vector3 input = {7, 2, 1};
	Matrix matrix = {
		4, 3, 1, 0,
		1, -2, 3, 0,
		5, 7, 0, 0,
		0, 0, 0, 1
	};

	Vector3 output;
	Vector3 right_output = {35, 6, 49};

	//output = matrix * input
	output = Vector3Transform(input, matrix);

	print_matrix3("matrix", matrix);
	print_vector("input vector", input);
	print_vector("expect result = matrix * input", right_output);

	printf("\n");
	print_vector("Vector3Transform calc result", output);

	printf("\n");
}

/**
 * matrix * matrix
  */
void test_matrix_product_matrix(void)
{
	Matrix A = {
		1,  1,  1, 0,
		1,  1, -1, 0,
		1, -1,  1, 0,
		0,  0,  0, 1
	};

	Matrix B = {
		1,   2, 3, 0,
		-1, -2, 4, 0,
		0,   5, 1, 0,
		0,   0, 0, 1
	};

	Matrix expectC = {
		0,  5, 8, 0,
		0, -5, 6, 0,
		2,  9, 0, 0,
		0,  0, 0, 1
	};
	Matrix A_turn;
	A_turn = MatrixTranspose(A);

	printf("test matrix product matrix start\n");
	print_matrix3("matrix A", A);
	print_matrix3("Transposes A", A_turn);

	print_matrix3("matrix B", B);
	print_matrix3("expect A_turn * B", expectC);

	expectC = matrxiMul(A, B); //A_turn = A
	print_matrix3("\n function MatrixMultiply calc result", expectC);

	printf("test matrix product matrix end\n\n");
}



int main(int argc, char** argv)
{
	test_dot_product();
	test_matrix_product_vector();
	test_matrix_product_matrix();
    return 0;
}

